﻿#include <iostream>

using namespace std;

class AbstractCommonInterface {
public :
    virtual void run() = 0;
};

class MySystem :public AbstractCommonInterface
{
public:
    virtual void run() {
        cout << "system start up" << endl;
    }
};

class MySystemProxy :public AbstractCommonInterface
{
public:
    MySystemProxy(string username, string passwd)
    {
        this->m_user = username;
        this->m_passwd = passwd;
        this->m_pMySystem = new MySystem();
    }

    virtual ~MySystemProxy()
    {
        if (m_pMySystem != nullptr)
        {
            delete m_pMySystem;
        }
    }

    bool CheckPasswd()
    {
        if (this->m_user == "admin" && this->m_passwd == "admin")
        {
            return true;
        }

        return false;
    }
    virtual void run()
    {
        if (CheckPasswd() == true && m_pMySystem != nullptr)
        {
            cout << "start up" << endl;
            m_pMySystem->run();
        }
    }
private:
    string m_user;
    string m_passwd;
    MySystem *m_pMySystem;
};

int main()
{
    MySystemProxy* proxy = new MySystemProxy("admin", "admin");
    proxy->run();

    delete proxy;
    return 0;
}
